package com.ccp.dev.workflow.listener;

import com.ccp.dev.core.util.AppUtil;
import com.ccp.dev.workflow.model.TaskOpinion;
import com.ccp.dev.workflow.service.BpmProStatusService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

/**
 * ClassDescribe:
 * 自动任务监听器
 * @author :wangcheng
 * Date: 2019-05-13
 */
@Component
public class AutoTaskListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution execution) {
        String nodeId = execution.getCurrentActivityId();
        String processDefinitionId = execution.getProcessDefinitionId();
        BpmProStatusService bpmProStatusService = (BpmProStatusService) AppUtil.getBean("bpmProStatusService");
        String processInstanceId = execution.getProcessInstanceId();
        // 记录节点运行状态
        bpmProStatusService.addOrUpd(processDefinitionId, processInstanceId, nodeId, TaskOpinion.STATUS_EXECUTED);
    }
}
